<template>
  <div>
    <div class="login-all">
      <!-- <div class="all-bei">
        <img src="'../../static/img/登录背景图.png'" alt="">
      </div> -->
      <div class="logo">
        <img src="static\img\logo2.png" alt="">
      </div>
      <div class="input">
        <el-form
          :model="ruleForm"
          status-icon
          :rules="rules"
          ref="ruleForm"
          label-width="100px"
          class="demo-ruleForm form"
        >
          <el-form-item prop="pass">
            <i class="el-icon-user"></i>
            <el-input placeholder="用户名" v-model="ruleForm.pass" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item prop="checkPass">
            <i class="el-icon-lock"></i>
            <el-input
              placeholder="密码"
              type="password"
              v-model="ruleForm.checkPass"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button class="tijiao" type="primary" @click="submitForm('ruleForm')">登录</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>
<script>
import http from '../api';
export default {
  data() {
    var validatePass = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入用户名'));
      } else {
        if (this.ruleForm.checkPass !== '') {
          this.$refs.ruleForm.validateField('checkPass');
        }
        callback();
      }
    };
    var validatePass2 = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入密码'));
      } else {
        callback();
      }
    };

    return {
      username: '',
      password: '',
      ruleForm: {
        pass: '',
        checkPass: '',
      },
      rules: {
        pass: [{ validator: validatePass, trigger: 'blur' }],
        checkPass: [{ validator: validatePass2, trigger: 'blur' }],
      },
    };
  },
  methods: {
    onSubmit(values) {
      console.log('submit', values);
    },

    submitForm(formName) {
      console.log(this.ruleForm.pass);
      this.$refs[formName].validate((valid) => {
        if (valid) {
          http
            .userLogin({
              admin_account: this.ruleForm.pass,
              admin_password: this.ruleForm.checkPass,
              admin_lastloginstate: 1,
            })
            .then((res) => {
              console.log(res);
              console.log('这是', res.data);
              sessionStorage.setItem('userToken', res.data.userToken);
              sessionStorage.setItem('people_id', res.data.people_id);
              sessionStorage.setItem('people_name', res.data.people_name);
              sessionStorage.setItem('people_url', res.data.people_url);

              this.$router.push({
                name: '主页',
              });
            });
        } else {
          console.log('登录失败');
          return false;
        }
        //滑动验证

        // 通过验证后提交
        // TO DO ...
        // this.$message.success("验证成功，可提交");
      });
    },
  },
};
</script>
<style scoped>
/* *{
  margin: 0;
  padding: 0;
} */
.all-bei{
  width: 100%;
  /* height: 60rem; */
  position: relative;
}
.all-bei img{
  /* width: 10rem;
  height: 6rem;
  position: absolute;
  z-index: -1; */
}
.van-cell >>> .van-field >>> .van-field--error {
  width: 70%;
  height: 4rem;
  border-radius: 5%;
  background: red;
}
.logo{
  width: 10rem;
  margin-top: 1rem;
  margin-left: -1rem;
  /* height: 10rem; */
}
.logo img{
   width: 40rem;
   /* background-color: burlywood; */
  /* height: 25rem; */
}
.login-all {
  width: 100%;
  height: 67rem;
  overflow: hidden;
  position: relative;
  /* display: flex;
 flex-direction: column;
 justify-content: space-evenly; */
  /* align-items: center; */
  background-image: url('../../static/img/登录背景图.png');
  background-size:cover ;
  /* background-position: 1rem; */
}
.tijiao {
  width: 27.5rem;
  margin: 0 auto;
  /* position: absolute; */
  /* top: 6rem; */
  /* background: red;   */
}
.form {
  /* margin-top: 2rem;  */
  position: relative;
  left: -4.3rem;
}
.el-icon-user {
  font-size: 1.8rem;
  color: #c0c4cc;
  position: absolute;
  z-index: 1;
  top: 1rem;
  left: 1rem;
}
.el-icon-lock {
  font-size: 1.8rem;
  color: #c0c4cc;
  position: absolute;
  z-index: 1;
  top: 1rem;
  left: 1rem;
}
.el-input >>> .el-input__inner {
  padding-left: 3.5rem;
}
.input {
  /* text-align: center; */
  /* margin-top: 75%; */
  margin-top: -5rem;
}
</style>